<template>
  <el-card style="margin-bottom: 15px">
    <el-form :inline="true" :disabled="!isDisabled">
      <el-form-item label="一级分类">
        <el-select placeholder="请选择" v-model="category1Id">
          <el-option
            v-for="c1 in categoryStore.category1List"
            :key="c1.id"
            :label="c1.name"
            :value="c1.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select placeholder="请选择" v-model="category2Id">
          <el-option
            v-for="c2 in categoryStore.category2List"
            :key="c2.id"
            :label="c2.name"
            :value="c2.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select placeholder="请选择" v-model="category3Id">
          <el-option
            v-for="c3 in categoryStore.category3List"
            :key="c3.id"
            :label="c3.name"
            :value="c3.id"
          />
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script lang="ts">
export default {
  name: 'CategorySelector',
  props: {
    isDisabled: {
      default: false,
      type: Boolean,
    },
  },
}
</script>
<script lang="ts" setup>
import { onMounted, computed } from 'vue'
import { useCategoryStore } from '@/stores/category'
const categoryStore = useCategoryStore()
onMounted(() => {
  categoryStore.getCategory1ListData()
  console.log(
    categoryStore.category1Id,
    categoryStore.category2Id,
    categoryStore.category3Id
  )
})
const category1Id = computed({
  get() {
    return categoryStore.category1Id as number
  },
  set(val: number) {
    categoryStore.getCategory2ListData(val)
  },
})
const category2Id = computed({
  get() {
    return categoryStore.category2Id as number
  },
  set(val: number) {
    categoryStore.getCategory3ListData(val)
  },
})
const category3Id = computed({
  get() {
    return categoryStore.category3Id as number
  },
  set(val: number) {
    categoryStore.setCategory3Id(val)
  },
})
</script>

<style scoped>
.el-form-item {
  margin-bottom: 0;
}
</style>
